package com.dengyafei.service.impl;

import com.dengyafei.bean.EnterpriseInfoEntity;
import com.dengyafei.bean.EnterpriseInfoEntityExample;
import com.dengyafei.constant.RecommendConstant;
import com.dengyafei.domin.dto.EnterpriseInfoInsertDTO;
import com.dengyafei.domin.dto.EnterpriseInfoSearchDTO;
import com.dengyafei.domin.dto.EnterpriseInfoUpdateDTO;
import com.dengyafei.domin.dto.EnterpriseQueryByNameDTO;
import com.dengyafei.domin.vo.EnterpriseInfoInsertVO;
import com.dengyafei.domin.vo.EnterpriseInfoSearchVO;
import com.dengyafei.domin.vo.EnterpriseInfoUpdateVO;
import com.dengyafei.domin.vo.EnterpriseQueryByNameVO;
import com.dengyafei.helper.BeanHelper;
import com.dengyafei.mapper.EnterpriseEntityMapper;
import com.dengyafei.mapper.EnterpriseInfoEntityMapper;
import com.dengyafei.service.EnterpriseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author 邓亚非
 */
@Service
public class EnterpriseInfoServiceImpl implements EnterpriseInfoService {

    @Autowired
    EnterpriseInfoEntityMapper enterpriseInfoEntityMapper;

    @Autowired
    EnterpriseEntityMapper enterpriseEntityMapper;



    /**
     * 企业入驻
     *
     * @param enterpriseInfoInsertVO
     * @return
     */
    @Override
    public Integer enterpriseInfoInsert(EnterpriseInfoInsertVO enterpriseInfoInsertVO) {
        EnterpriseInfoInsertDTO enterpriseInfoInsertDTO = BeanHelper.copyProperties(enterpriseInfoInsertVO, EnterpriseInfoInsertDTO.class);
        Integer integer = enterpriseInfoEntityMapper.insertEnterpriseInfo(enterpriseInfoInsertDTO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            return RecommendConstant.ENTERPRISE_SETTLED_FAILURE;
        }
        return integer;
    }

    /**
     * 查询公司信息
     *
     * @param
     * @return
     */
    @Override
    public EnterpriseInfoEntity queryByName(String userInfo) {

        String s = enterpriseEntityMapper.EnterpriseQueryByHname(userInfo);
        if (ObjectUtils.isEmpty(s)) {
            return new EnterpriseInfoEntity();
        }
        EnterpriseInfoEntity enterpriseInfoEntity = enterpriseInfoEntityMapper.queryByEname(s);
        if (ObjectUtils.isEmpty(enterpriseInfoEntity)) {
            return new EnterpriseInfoEntity();
        }
        return enterpriseInfoEntity;
    }

    /**
     * 修改企业信息
     *
     * @param enterpriseInfoUpdateVO
     * @return
     */
    @Override
    public Integer updateEnterpriseInfo(EnterpriseInfoUpdateVO enterpriseInfoUpdateVO) {
        EnterpriseInfoEntity enterpriseInfoEntity = BeanHelper.copyProperties(enterpriseInfoUpdateVO, EnterpriseInfoEntity.class);
        Integer i = enterpriseInfoEntityMapper.updateByPrimaryKey(enterpriseInfoEntity);
        if (!i.equals(RecommendConstant.OPERATION_SUCCESS)) {
            return RecommendConstant.ENTERPRISE_UPDATE_FAILURE;
        }
        return i;
    }

    /**
     * 查询所有的公司信息
     * @return
     */
    @Override
    public List<EnterpriseInfoEntity> queryAll() {
        return enterpriseInfoEntityMapper.queryAll();
    }

    /**
     * 条件查询
     * @param enterpriseInfoSearchVO
     * @return
     */
    @Override
    public List<EnterpriseInfoEntity> queryByParams(EnterpriseInfoSearchVO enterpriseInfoSearchVO) {
        EnterpriseInfoSearchDTO enterpriseInfoSearchDTO = BeanHelper.copyProperties(enterpriseInfoSearchVO, EnterpriseInfoSearchDTO.class);
        return enterpriseInfoEntityMapper.queryByParams(enterpriseInfoSearchDTO);
    }

    /**
     * 查询所有企业
     * @return
     */
    @Override
    public List<EnterpriseInfoEntity> queryEnterpriseInfos() {
        return enterpriseInfoEntityMapper.queryEnterpriseInfos();
    }
}